<template>
  <!-- 知识库统计 -->
  <div class="knowledge-statistics-box" v-loading="loading">
    <el-row :gutter="10">
      <el-col :span="12">
        <div class="item">
          <div class="num">{{ allNum || 0 }}</div>
          <div class="txt">所有知识</div>
        </div>
      </el-col>
      <el-col :span="12">
        <div class="item">
          <div class="num">{{ myNum || 0 }}</div>
          <div class="txt">我提交的知识</div>
        </div>
      </el-col>
    </el-row>
  </div>
</template>

<script setup lang="ts" name="KnowledgeStatisticsBox">
import { ref, onMounted } from "vue";
import { countKnowledge } from "@/api/modules/index";

const allNum = ref(0);
const myNum = ref(0);
const loading = ref(false);

onMounted(() => {
  loading.value = true;
  // 所有知识数量
  countKnowledge({
    flag: ""
  })
    .then((res: any) => {
      loading.value = false;
      allNum.value = res;
      // 我提交的知识数量
      countKnowledge({
        flag: "my"
      }).then((res: any) => {
        myNum.value = res;
      });
    })
    .catch(() => {
      loading.value = false;
    });
});
</script>

<style scoped lang="scss">
.knowledge-statistics-box {
  box-sizing: border-box;
  width: 100%;
  padding: 0 10px 10px;
  text-align: center;
  .item {
    box-sizing: border-box;
    padding: 15px 0 18px;
    margin-top: 10px;
    background-color: var(--el-menu-active-bg-color);
    background-size: 100% 100%;
    border-radius: 10px;
    transition: all 0.3s;
  }
  .num {
    font-size: 20px;
    font-weight: bold;
    color: $primary-color;
  }
  .txt {
    margin-top: 5px;
    font-size: 14px;
  }
}
</style>
